
<form class="layui-form">
    <a href="/admin/vote/add" class="layui-btn">新增</a>

    <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
    <thead>
    <tr>
        <td>ID</td>
        <td>标题</td>
        <td>参与人数</td>
        <td>状态</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {volist name="vote_list" id="vo"}
    <tr data-index="0" class="">
        <td>{$vo.id}</td>
        <td>{$vo.title}</td>
        <td>{$vo.voter}</td>
        <td>
            <div class="layui-form-item" style="padding: 0">
                <label class="layui-form-label">是否开启</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="close" data-id="{$vo.id}" {if condition="$vo.status"} checked {/if} lay-skin="switch" lay-text="ON|OFF">
                </div>
            </div>
        </td>
        <td width="180">
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
            <a href="/admin/vote/edit?id={$vo.id}" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs delEnv" data-id="{$vo.id}" lay-event="del">删除</a>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>
</form>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$  = layui.jquery;
        $('.delEnv').click(function(){
            let id = $(this).data('id');
            layer.confirm('是否确定要删除？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.get('/admin/vote/del?id=' + id);
                location.reload();
            });
        })
        //监听指定开关
        form.on('switch(switchTest)', function(data){
            alert(0)
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            let id = $(this).data('id');
            $.get('/admin/vote/editStatus?id=' + id);
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });
</script>
